package com.cml.dm.admin.service.sql;

import com.cml.dm.admin.entity.DmExeLogger;
import com.cml.dm.admin.entity.DmMetadata;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Primary
public class DefaultBackupSqlGenerateService extends AbstractBackupSqlGenerateService {

    @Override
    public List<String> doSqlGenerate(DmMetadata dmMetadata, DmExeLogger dmExeLogger, Object extParameter) {
        List<String> sqlList = new ArrayList<>();
        StringBuilder sql = new StringBuilder();
        sql.append(dmMetadata.getBackupSql() + " where " +dmMetadata.getOrgId() +"="+dmExeLogger.getOrgId());
        if(null != dmMetadata.getShardingColumn()){
            sql.append(" and "+ dmMetadata.getShardingColumn()+"="+dmExeLogger.getShardingColumn());
        }
        sqlList.add(sql.toString());
        return sqlList;
    }
}
